Javascript object collection.
NPM |
YARN
Built from Lodash's object functions api.
so instead of _.extend(obj, data)
you do data.extend({})
.
All lodash helpers that mutates object returns this
When to use ObjectCollection.
ObjectCollection is best used when accessing large objects e.g Api data, Your config object e.t.c
Usage
const Obj = require("object-collection");
let data = new Obj();
const User = {name: "John", age: 32, gender: "male"};
const user = new Obj(User);
const user = Obj.use(User);
user.has("name")
user.pick(['name', 'age']);
user.set({hobbies: ['code', 'eat', 'sleep']});
You get the idea right? All object helpers in lodash
are available on this
We also added a few more helpers. e.g
If a path in your object holds an object
we can access it as a collection using .path
helper
user.set('contact_details', {
address: 'No 1 Astro World',
phone: '+123456789',
country: 'US',
});
user.path("contact_details");
user.get("contact_details.address");
user.path("contact_details").get('address');
user.path("contact_details").pick(['phone', 'US'])
Full Docs coming soon